import React, { Component } from 'react'
import {
  Route,
  Redirect,
  Switch
}from 'react-router-dom'

// 引入各个页面
import Home from '../Home'
import User from '../User'
import Manage from '../Manage/Manage'
import Right from '../Manage/Right'
import Role from '../Manage/Role'
import List from '../Article/List'
import Category from '../Article/Category'
import Create from '../Article/Create'
import Preview from '../Article/Preview'
import Update from '../Article/Update'
import NotFind from '../NotFind'

import Sidermenu from './Sidermenu'
import Headernave from './Headnav'

// 引入antd组件
import { Layout  } from 'antd';
//引入CSS
import './Dashboard.css'

const { Content } = Layout;


export default class index extends Component {
  
  render() {
    // 获取当前用户权限
    var roleType = JSON.parse(localStorage.getItem("users")).roleType
    return (
      <Layout className="layout">
        <Sidermenu/>
        <Layout className="site-layout">
          <Headernave/>
          <Content
            className="site-layout-background"
            style={{
              margin: '24px 16px',
              padding: 24,
              minHeight: 280,
            }}
          >
            {/* Content */}
            <Switch>
              <Route path="/home" component={ Home }/>
              {/* 用户管理-用户列表 */}
              {/* 权限为3 - 超级管理员可见 */}
              {  
                  roleType === 3?
                  <Route path="/user" component={ User }/>
                  :
                  null
              }
               {/* 文章管理 -列表 ,预览(动态路由组件) */}
              <Route path="/article-manage/list" component = {List}/>

              {/* 文章分类页面 - 超级管理员，管理员可见*/}
              {  
                  roleType >= 2?
                  <Route path="/article-manage/category" component = {Category}/>
                  :
                  null
              }
              <Route path="/article-manage/create" component = {Create}/>
              <Route path="/article-manage/preview/:id" component = {Preview}/>
              <Route path="/article-manage/update/:id" component = {Update}/>
               {/* 权限管理- 角色和权限 */}
               {/* 权限为3 - 超级管理员，管理员可见 */}
               {  
                  roleType >= 2?
                  <Route path="/right-manage" render = {()=>
                    <Manage>
                      <Switch>
                        <Route path="/right-manage/rights" component={ Right }/>
                        <Route path="/right-manage/roles" component={ Role }/>
                        <Redirect from="/right-manage" to="/manage/roles" exact/>
                      </Switch>
                    </Manage>
                  }/>
                  :
                      null
                }
                {/* 重定向 */}
              <Redirect from="/" to="/home" exact/>
              <Route path="*"  component={ NotFind } />
            </Switch>
          </Content>
        </Layout>
      </Layout>
     )
  }
}
